import { RECEIVE_ADDRESS, RECEIVE_CATEGORYS, RECEIVE_SHOPS ,USER_INFO,LOGOUT,

    RECEIVE_GOODS,
    RECEIVE_RATINGS,
    RECEIVE_INFO

} from './mutation-types'

// actions: {
//     increment (context) {
//       context.commit('increment')
//     }
//   }


import {reqAddress, reqCategorys, reqShops,reqPwdLogin,reqPhoneLogin,

    reqShopGoods,
    reqShopInfo,
    reqShopRatings

} from '../api/index'
export  default {
     async  getCategorys(context) {


         let result=  await reqCategorys();
        //  console.log(result.data);
         let categorys=result.data
        context.commit(RECEIVE_CATEGORYS,categorys)
    },

    async getShops( context,shopData){   //shopData 是一个经纬度 对象

        let result =await reqShops(  shopData )
        console.log(result.data)
        let shops=result.data;

        context.commit(RECEIVE_SHOPS,shops)

    },

 //登录 获取用户信息
 async asyncgetuserLogin(context, userInfos) {
    let userInfo = await reqPwdLogin(userInfos)

    context.commit(USER_INFO, userInfo.data)
},

//手机号码短信验证登录 

async asyncPhoneLogin(context, dataPhone) {
    let userInfo = await reqPhoneLogin(dataPhone);
    console.log(userInfo)
    if (userInfo.code == 0) {
        context.commit(USER_INFO, userInfo.data)
    }
},


//退出  
getLogout(context) {

    context.commit(LOGOUT)
},




    // 商家个人信息 

    async getShopInfo(context) {
        let result = await reqShopInfo()
        if (result.code == 0) {
            let info = result.data
            context.commit(RECEIVE_INFO, { info })
        }


    },
    //商家商品信息
    async getShopGoods(context,callback) {
        let result = await reqShopGoods()
        if (result.code == 0) {
            let goods = result.data
            context.commit(RECEIVE_GOODS, {goods})
            callback && callback()
        }


    },
    //商家评论信息
    async getShopRatings({commit}) {
        let result = await reqShopRatings()
        if (result.code == 0) {
            let ratings = result.data
          commit(RECEIVE_RATINGS, { ratings })
         
        }


    }


}